|
|
|
|
|
|
|
For index = 0 To lstServices.ListCount - 1
If lstServices.Selected(index) Then
currententry = lstServices.List(index)
For Each svcstat In ServiceCollection
' Match based on the service name
If InStr(currententry, svcstat.Name & ":") = 1 Then
ChangesInProgress.Add sc.OpenService(svcstat, _
SERVICE_START Or SERVICE_STOP), svcstat.Name
Exit For
End If
Next
End If
Next index
End Function |
|
|
|
|
|
|
|
|
The codes to stop, start, and restore services are very similar to each other. After obtaining a list of selected services, they query the service for its current state and remove any services from the ChangesInProgress collection that are already in the requested state. The ServiceControl or StartService method is used to stop or start the service if necessary. If any services remain in the ChangesInProgress collection, the EnablePanel function is called to enter the Execution state. |
|
|
|
|
|
|
|
|
' Stops the selected services
Private Sub cmdStop_Click()
Dim so As ServiceObject
Dim stat As ServiceStatus
Dim starttimer As Boolean
Dim RemoveThis As Boolean
Dim res&
Call OpenSelectedServices
For Each so In ChangesInProgress
Set stat = so.QueryServiceStatus
If stat.CurrentState <> SERVICE_STOPPED Then
res = so.ServiceControl(SERVICE_CONTROL_STOP)
If res <> 0 Then
starttimer = True
Else
RemoveThis = True
End If
Else
RemoveThis = True
End If
If RemoveThis Then ChangesInProgress.Remove stat.Name |
|
|
|
|
|